/*
 * Team 1 Project - Palo Alto Bicycle Club
 * Author: Archana Nagarkatti
 * Class: COIN 71
 * Filename: announcement.js 
 * Date Created: 3/15/2009
 * Functionality: List all the announcements.
 * Modification History:
 */

/*
window.onload=function()
{	
    var contentLoader = new net.ContentLoader("announcements.xml", buildList);
}	
*/

// ***** Deleted global var URL... moved directly to 



//builds the list of announcements by accessing the responseXML                
function buildList () {	
    responseXML = this.req.responseXML.documentElement;    
    listAnnouncements(responseXML);    
}  
/*
 * lists all the previously posted announcements by 
 * pulling it from announcements.xml file
 */ 
function listAnnouncements(resp){
    //get announcement div node
	var announcementNode = document.getElementById("announcement");

    var array = resp.getElementsByTagName('announcement');	
	for (i=array.length-1;i>=0; --i)
	{
		$title = array[i].getElementsByTagName('title')[0].firstChild.nodeValue ;
		$author = array[i].getElementsByTagName('author')[0].firstChild.nodeValue ;
		$postdate = array[i].getElementsByTagName('postdate')[0].firstChild.nodeValue ;
		$message = array[i].getElementsByTagName('message')[0].firstChild.nodeValue ;
		
		addElement(announcementNode, "h4", $title);				
		addElement(announcementNode, "p", $message);	
		addElement(announcementNode, "br", "");
		addElement(announcementNode, "i", "Posted By: ");
		addElement(announcementNode, "label", $author);
		addElement(announcementNode, "i", " On: ");
		addElement(announcementNode, "label", $postdate);	
	}	
}
//adds elements for various attributes to the announcement parent node
function addElement(parentNode, element, text){
	var childEl = document.createElement(element);
	if (text != ""){
		childEl.appendChild(document.createTextNode(text));
	}
	parentNode.appendChild(childEl);
}


